package io.xp.kata.gildedrose;


import org.junit.Test;
import sun.misc.Resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;


import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * 功能描述
 */
public class GildedRoseSafetyNet {

    @Test
    public void should_always_align_with_baseline() throws IOException {


        String output = TexttestFixture.getBaseLine();

// 获取资源文件的URL
        String baseline = null;

        ClassLoader classLoader = getClass().getClassLoader();
        URL resourceUrl = classLoader.getResource("baseline.txt");
        InputStream inputStream = classLoader.getResourceAsStream("baseline.txt");

// 读取资源文件内容
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            StringBuilder stringBuilder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line).append(System.lineSeparator());  // 使用 System.lineSeparator() 添加行分隔符
            }
            String allLinesAsOneString = stringBuilder.toString();
            baseline = allLinesAsOneString;
            // System.out.println(allLinesAsOneString);
        } catch (IOException e) {
            e.printStackTrace();
        }

        // System.out.println(readContext);

        assertThat(output, is(baseline));


    }
}
